package com.tiyende.kash.loop.ui.presenter

import com.tiyende.kash.loop.R
import com.tiyende.kash.loop.common.CommonPresenter
import com.tiyende.kash.loop.configs.TiyendeApiUrl
import com.tiyende.kash.loop.request.IHttpCallback
import com.tiyende.kash.loop.ui.contract.IViewContract
import org.json.JSONObject

/**
 * TiyendeCredit
 * @Author wwdeng
 * @CreateTime: 2024/11/27 16:26
 * @Annotation：意见反馈 Presenter 实现
 */
class TiyendeFeedbackPresenter(private val iView: IViewContract.ITiyendeFeedbackView): CommonPresenter(iView) {

    private val typeTitleList = arrayListOf(R.string.tiyende_feedback_type_suggest,R.string.tiyende_feedback_type_bug,R.string.tiyende_feedback_type_repayment_issues,R.string.tiyende_feedback_type_other)
    private val typeValueList = arrayListOf("SUGGEST","BUG","PAYMENT","OTHER")

    //反馈类型列表
    private var typeList: ArrayList<JSONObject>? = null

    /**
     * 获取意见反馈类型
     */
    fun loadFeedbackQuestionTypeListAction() {
        if (typeList == null){
            typeList = arrayListOf()
        }
        typeList?.clear()
        for (i in 0..<typeTitleList.size){
            val obj = JSONObject()
            obj.put("title", typeTitleList[i])
            obj.put("value", typeValueList[i])
            obj.put("isSelect",false)
            typeList?.add(obj)
        }
        typeList?.let {
            iView.setTiyendeFeedbackQuestionTypeList(it)
        }
    }

    /**
     * 提交反馈
     */
    fun submitFeedbackAction(params: JSONObject){
        val httpUrl = TiyendeApiUrl.getTiyendeHttpUrl()
        doHttpPostAction(httpUrl,params,object : IHttpCallback {
            override fun onRequestSuccess(data: JSONObject) {
                val msg = data.optString("msg")
                iView.showTiyendeToast(msg)
                iView.showTiyendeFeedbackSubmitSuccess()
            }

            override fun onRequestError(error: JSONObject) {
            }

            override fun onRequestFinish() {
                iView.hiddenTiyendeLoading()
            }
        })
    }

    /**
     * 获取全部问题类型列表
     */
    fun getUserAdviseTypeList(): ArrayList<JSONObject>?{
        return typeList
    }
}